package com.control;

import java.io.IOException;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.List;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import com.clases.base.Boleto;
import com.jdbc.BDManagement;


public class CargarBoleto extends HttpServlet {
	private static final long serialVersionUID = 1L;
    private BDManagement bdm = new BDManagement();

    protected void cargaBol(HttpServletRequest request, HttpServletResponse response)
            throws ServletException, IOException {
    	
    	HttpSession session = request.getSession();
    	String boleteria = (String) session.getAttribute("user");
    	int idBoleto = Integer.parseInt(request.getParameter("idBoleto"));
    	int asiento = Integer.parseInt(request.getParameter("asiento"));
    	Boleto boleto = new Boleto(idBoleto, request.getParameter("fechaViaje"), asiento, request.getParameter("partida"), request.getParameter("destino"), request.getParameter("horario"), boleteria);
    	bdm.setBoleto(boleto);
    	response.sendRedirect("cargaDestinosCochesBoletos");
    	
    	//this.getServletContext().getRequestDispatcher("cargaDestinosCochesBoletos").forward(request, response);
    	//this.addRow(boleto);   	
    	
    }
    
    
    /*public void addRow(Boleto bol){
    	try {
    		String sentencia = "INSERT INTO boletos (idBoleto,fechaViaje,fechaActual,asiento,partida,destino,horario,boleteria)  VALUE  ('"+bol.getIdBoleto()+"','"+bol.getFechaViaje()+"','"+bol.getFechaActual()+"','"+bol.getAsiento()+"','"+bol.getPartida()+"','"+bol.getDestino()+"','"+bol.getHorario()+"')";
			bdm.getSt().executeUpdate(sentencia);
		} catch (SQLException e) {
			e.printStackTrace();
		}
    	
    }*/
	
    @Override
    protected void doGet(HttpServletRequest request, HttpServletResponse response)
            throws ServletException, IOException {
        cargaBol(request, response);
    }


    @Override
    protected void doPost(HttpServletRequest request, HttpServletResponse response)
            throws ServletException, IOException {
        cargaBol(request, response);
    }

   
    @Override
    public String getServletInfo() {
        return "Short description";
    }

}
